# 1.获取字典中的值：获取下列字典键为 'history' 的值
# sampleDict = {"class":{"student":{"name":"Mike","marks":{"physics":70,"history":80}}}}
# for i in (sampleDict.values()) :
#     for j in (i.values()) :
#         print(j)
#         print(type(j))
#         for k in (j.values()) :
#             print(k)
#             print(type(k))
#             k.pop(0)
#             # 如何处理字符串Mike
#             for a in (k.values()) :
#                 print(a["history"])
# values1=sampleDict["class"]["student"]["marks"]["history"]
# print(values1)

# 2.请将元组 v1 = (11,22,33) 中的所有元素追加到列表 v2 = [44,55,66] 中
# v1=(11,22,33)
# v2=[44,55,66]
# list1=list(v1)
# list1.extend(v2) #使用extend在列表后追加多个元素
# print(list1)
# print(type(list1))

# 3.已知列表：
# list1 = ['life','is','short']
# list2 = ['you','need','python']
# list3 = [1,2,3,4,5,3,4,2,1,5,7,9]
# 完成以下操作：
# （1）把上述三个列表构造为⼀个集合 set1
# （2）输出集合的⻓度
# （3）把python从集合中移除
# list1 = ['life','is','short']
# list2 = ['you','need','python']
# list3 = [1,2,3,4,5,3,4,2,1,5,7,9]
# # (1)
# list4=list1+list2+list3
# print(list4)
# set1=set(list4)
# print(set1)
# # (2)
# print(len(set1))
# # (3)
# set1.remove("python")
# print(set1)

# 4.已知列表li= [11,22,100,33,44,66,55,77,88,99,90] ,将所有⼤于 66 的值保存⾄字典的第⼀
# 个key对应的列表中，将⼩于 66 的值保存⾄第⼆个key对应的列表中。
# 输出结果：{'key1':[100,77,88,99,90],'key2':[11,22,33,44,55]}
# li= [11,22,100,33,44,66,55,77,88,99,90]
# list1=[]
# list2=[]
# for i in li : # 使i遍历列表li
#     if i > 66 :
#         list1.append(i) # 如果i大于66则加入到list1中
#     elif i < 66 :
#         list2.append(i) # 如果i小于66则加入到list2中
# d1={"key1":list1,"key2":list2}
# print(d1)

# 5.已知列表list1 = [11,22,11,33,44,55,66,55,66],
# 统计列表中每个元素出现的次数，⽣成⼀个字典
# 输出结果：{11:2,22:1.....}
# 注：顺序不要求
# 死写
# list1 = [11,22,11,33,44,55,66,55,66]
# count1=0
# count2=0
# count3=0
# count4=0
# count5=0
# count6=0
# for i in list1 :
#     if i == 11 :
#         count1+=1
#     elif i == 22 :
#         count2+=1
#     elif i == 33 :
#         count3+=1
#     elif i == 44 :
#         count4+=1
#     elif i == 55 :
#         count5+=1
#     elif i == 66:
#         count6+=1
# d1={11:count1,22:count2,33:count3,44:count4,55:count5,66:count6}
# print(d1)
# print(type(d1))

# 活写
# list1 = [11,22,11,33,44,55,66,55,66]
# dict1={}
# for i in list1 : # 使i遍历list1中
#     dict1[i]=list1.count(i) # list1.count(i)表示统计元素i在list1中出现的次数，dict[i]表示对应的元素在list1是哪个数
# print(dict1)

# 6.已知字典d1={"subjects":[{"rate":"7.4","cover_x":640},{"rate":"6.0","cover_x":1080}]}
# 处理显⽰成如下格式输出：
# 7.4 640
# 6.0 1080
# 第一种效果
# d1={"subjects":[{"rate":"7.4","cover_x":640},{"rate":"6.0","cover_x":1080}]}
# d1={"subjects":[{"rate":"7.4","cover_x":640},{"rate":"6.0","cover_x":1080}]}
# for i in d1.values() : # 使i遍历d1的值，一个列表
#     for j in i : # 使j遍历i的值，即两个字典
#         for k in j.values() : # 使k遍历j的值
#             print(k,end=" ") # 最后输出k的值
#         print() # 每输出完一个字典的值就换行

# 第二种效果
# d1={"subjects":[{"rate":"7.4","cover_x":640},{"rate":"6.0","cover_x":1080}]}
# for i in (d1.values()) :
#     dict1=dict(i[0])
#     dict2=dict(i[1])
#     print(dict1)
#     print(dict2)
# print(dict1["rate"],dict1["cover_x"])
# print(dict2["rate"],dict2["cover_x"])

# d1={"subjects":[{"rate":"7.4","cover_x":640},{"rate":"6.0","cover_x":1080}]}

# for i in d1.keys(): # 遍历字典d1的所有键（如i="subjects"）
#     for j in d1[i]: # j遍历d1[i]对应的列表（如j={"rate":"7.4", "cover_x":640}）
#         for k in j.keys(): # 遍历字典j的所有键（如k="rate", "cover_x"）
#             print(j[k],end=" ") # 打印j中键k对应的值（如"7.4", 640），空格分隔
#         print()  # 每处理完一个字典j后换行

# 7.已知如下数据
# d1 = {
# '192.168.1.1':{'cpu':'0.23','内存':'16','硬盘':'500'},
# '192.168.1.2':{'cpu':'3.22','内存':'64','硬盘':'700'},
# '192.168.1.3':{'cpu':'1.99','内存':'32','硬盘':'800'}
# }
# 处理显⽰成如下格式输出：
# 192.168.1.1: cpu 0.23 内存 16 硬盘 500
# 192.168.1.2: cpu 3.22 内存 64 硬盘 700
# 192.168.1.3: cpu 1.99 内存 32 硬盘 800
# d1 = {
# '192.168.1.1':{'cpu':'0.23','内存':'16','硬盘':'500'},
# '192.168.1.2':{'cpu':'3.22','内存':'64','硬盘':'700'},
# '192.168.1.3':{'cpu':'1.99','内存':'32','硬盘':'800'}
# }

# 拼接部分
# for ip,info in d1.items():
#     details = " ".join([f"{k} {v}" for k, v in info.items()])
#     print(f"{ip}: {details}")

# for i in d1.keys() :
#     print(i,end=": ")
#     for j in d1[i].keys() :
#         print(j,end=" ")
#         print(d1[i][j],end=" ")
#     print()

# for i in d1.keys() : # 使i遍历d1的ip部分即键部分
#     print(i,end=": ") # 打印ip部分并在后面在:与空格
#     for j in d1[i].keys() : # 
#         print(j,end=" ")
#         print(d1[i][j],end=" ")
#     print("")

# 8.有字符串"k: 1|k1:2|k2:3 |k3 :4" 处理成字典 {'k':1,'k1':2,'k3':4}
# 注：字符串替换使⽤replace函数
# d={}
# a1="k: 1|k1:2|k2:3 |k3 :4"
# a1=a1.replace(" ","")
# a1=a1.split("|")
# print(a1)
# for i in a1 :
#     j=i.split(":")
#     key,values=j
#     if key != "k2" :
#         d[key]=int(values)
# print(d)



# 1. ⽣成⼀个存放1-100之间个位数为3的数据列表
# print([f"{i:02d}" for i in range(1,101) if i%10 == 3])

# 2. 利⽤列表推导式将已知列表中的整数提取出来[17, 98, 34, 21]
# list_two = [True, 17, "hello", "bye", 98, 34, 21]
# list_two = [True, 17, "hello", "bye", 98, 34, 21]
# print([i for i in list_two if type(i) == int])

# 3. list_three=["good", "nice", "see you", "bye"]，根据列表利⽤推导式存放指定列表中
# 字符串的⻓度如下
# {'good':4, 'nice':4, 'see you':7, 'bye':3}
# list_three=["good", "nice", "see you", "bye"]
# print({i:len(i) for i in list_three })

# 4. ⽣成⼀个列表，其中的元素为'0-1'，'1-2'，'2-3'，'3-4'，'4-5'
# print([f"{(i-1)}-{i}" for i in range(1,6)])

# 5. 已知数据t1=((1,100),(2,30),(3,80),(4,234))
# 推导成列表[100,30,80,234]
# 推导成字典{1: 100, 2: 30, 3: 80, 4: 234}
# 推导成列表[{'name': 1, 'value': 100}, {'name': 2, 'value': 30}, {'name': 3, 'value': 80},
# {'name': 4, 'value': 234}]
# (1)
# t1=((1,100),(2,30),(3,80),(4,234))
# print([j for i in t1 for j in i if j > 4 ])
# print([i[1] for i in t1])
# (2)
# t1=((1,100),(2,30),(3,80),(4,234))
# print({ i:j for i,j in t1 })
# (3)
# t1=((1,100),(2,30),(3,80),(4,234))
# print([{f"name":i,"value":j}for i,j in t1])

# 6. 已知如下列表students，在列表中保存了6个学⽣的信息，根据要求完成下⾯的题⽬
# students = [
# {'name': '⼩花', 'age': 19, 'score': 90, 'gender': '⼥', 'tel':'15300022839'},
# {'name': '明明', 'age': 20, 'score': 40, 'gender': '男', 'tel':'15300022838'},
# {'name': '华仔', 'age': 18, 'score': 100, 'gender': '⼥', 'tel':'15300022839'},
# {'name': '静静', 'age': 16, 'score': 90, 'gender': '不明', 'tel':'15300022428'},
# {'name': 'Tom', 'age': 17, 'score': 59, 'gender': '不明', 'tel':'15300022839'},
# {'name': 'Bob', 'age': 18, 'score': 90, 'gender': '男', 'tel':'15300022839'}
# ]
# 打印学⽣分数列表
# 打印⼿机尾号是8的学⽣的名字列表
# 打印不及格的同学的所有信息列表，效果如下：
# ['明明', 20, 40, '男', '15300022838', 'Tom', 17, 59, '不明', '15300022839']

# students = [
# {'name': '⼩花', 'age': 19, 'score': 90, 'gender': '⼥', 'tel':'15300022839'},
# {'name': '明明', 'age': 20, 'score': 40, 'gender': '男', 'tel':'15300022838'},
# {'name': '华仔', 'age': 18, 'score': 100, 'gender': '⼥', 'tel':'15300022839'},
# {'name': '静静', 'age': 16, 'score': 90, 'gender': '不明', 'tel':'15300022428'},
# {'name': 'Tom', 'age': 17, 'score': 59, 'gender': '不明', 'tel':'15300022839'},
# {'name': 'Bob', 'age': 18, 'score': 90, 'gender': '男', 'tel':'15300022839'}
# ]
# (1)
# print([students[i]["score"] for i in range(0,len(students))])
# print([i["score"] for i in students])
# (2)
# print([students[i]["name"] for i in range(0,len(students))if students[i]["tel"][-1] == "8" ])
# print([i["name"] for i in students if i["tel"][-1] == "8"])
# (3)
# print([students[i][k] for i in range(0,len(students)) for k in students[i] if students[i]["score"] < 60])
# print([j for i in students if i["score"] < 60 for j in i.values()])








